//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Lampara.h"


//---------------------------------------------------------------------------

Lampara::Lampara(float r, float h){
        //double  base,double  top, double  height,int  slices,int  stacks, Color* c)
        //hay que rotar la pantalla porque se crea en el eje z
        pantalla = new Cilindro(r,r/2,h,10,10,new Color(AZUL));
        
        luzDir[0]=0;
        luzDir[1]=0;
        luzDir[2]=-1;
        luzDir[3]=0;

         luzPos[0] = 0;
         luzPos[1] = 0;
         luzPos[2] = h;
         luzPos[3] = 1;

        enabled = true;
        exponent = 0;
        this->r = r;
        this->h = h;
        calcularCutOff();
}

Lampara::~Lampara(){
        delete pantalla;
}

void Lampara::draw(){
        GLfloat luz2[] = { 1, 1, 1, 1 };

        CMatriz* m = this->getTAfin()->getMatriz();

        glPushMatrix();
                glMultMatrixf(m->getMatriz());
                pantalla->draw();

                glLightfv(GL_LIGHT1, GL_POSITION, luzPos);
                glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, luzDir);
                if (enabled){
                        glEnable(GL_LIGHT1);
                        calcularCutOff();

                }
                else
                        glDisable(GL_LIGHT1);
        glPopMatrix();

        glLightfv(GL_LIGHT1, GL_AMBIENT, luzPos);
        glLightfv(GL_LIGHT1, GL_DIFFUSE, luz2);
        glLightfv(GL_LIGHT1, GL_SPECULAR, luz2);
        glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, cutoff);
        glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, exponent);
}

#pragma package(smart_init)
